using System;
using Microsoft.Xna.Framework;
using TD.Interface.Credits;
using TD.Interface.Credits.Effects;

namespace TD.Interface
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class CreditsOverlay : DrawableGameComponent
    {
        private Word jiri;
        private Word bart;
        private Word mark;

        public CreditsOverlay(Game game) :
            base(game)
        {
            this.DrawOrder = 0x08F00000;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization logic here

            Library library = new Library(Game);
            Game.Components.Add(library);

            jiri = new Word(Game, "Jiri");
            jiri.Position = new Point(1040, 640);
            Game.Components.Add(jiri);

            bart = new Word(Game, "bart");
            bart.Position = jiri.Position;
            Game.Components.Add(bart);

            mark = new Word(Game, "mark");
            mark.Position = jiri.Position;
            Game.Components.Add(mark);

            LoadContent();

            base.Initialize();
        }

        private bool added = false;

        public override void Update(GameTime gameTime)
        {
            if (!added)
            {
                added = true;

                Effect slideA = new Efx_Special();
                slideA.Done += new OnDone(this.Slide_A);
                jiri.Effect = slideA;

                Effect slideB = new Efx_Special();
                slideB.Done += new OnDone(this.Slide_B);
                bart.Effect = slideB;

                Effect slideC = new Efx_Special();
                slideC.Done += new OnDone(this.Slide_C);
                mark.Effect = slideC;

                Slide_A();
            }

            base.Update(gameTime);
        }

        private void Slide_A()
        {
            Slide_Reset();
            jiri.Enabled = false;
            jiri.Visible = false;
            bart.Enabled = true;
            bart.Visible = true;
            mark.Enabled = false;
            mark.Visible = false;
        }

        private void Slide_B()
        {
            Slide_Reset();
            jiri.Enabled = false;
            jiri.Visible = false;
            bart.Enabled = false;
            bart.Visible = false;
            mark.Enabled = true;
            mark.Visible = true;
        }

        private void Slide_C()
        {
            Slide_Reset();
            jiri.Enabled = true;
            jiri.Visible = true;
            bart.Enabled = false;
            bart.Visible = false;
            mark.Enabled = false;
            mark.Visible = false;
        }

        private void Slide_Reset()
        {
            jiri.Reset();
            bart.Reset();
            mark.Reset();
        }

        protected override void OnVisibleChanged(object sender, EventArgs args)
        {
            if (Visible)
            {
                Slide_A();
            }
            else
            {
                jiri.Enabled = false;
                jiri.Visible = false;
                bart.Enabled = false;
                bart.Visible = false;
                mark.Enabled = false;
                mark.Visible = false;
            }
            base.OnVisibleChanged(sender, args);
        }
    }
}
